/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : friend_01.js                            
*  Description  : 친구요청
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-24  김효순    Created.  
*  2012-04-24  김효순    액션빼고 완료.  
*******************************************************************************/

jQuery(function($){
	// 리스트
	function clsList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsList.prototype = {
		_init: function(){
			$layer = $("div#container>section#main_content>article.my_friend_demand")
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			
			$layer.find("tbody").empty();
		}
		, setData: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $box = $layer.find("tbody");
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$box.empty();
			for(var i=0;i<this.listData.length;i++){
				$box.append($element.clone(true));
			}
			
			$box.find("tr").each(function(n){
				switch(thisClass.listData[n]["성별"]){
					case "남자":
						var szClass = "sex_m";
						break;
					case "여자":
						var szClass = "sex_w";
						break;
				}
				
				$(this).find("td:eq(0) img").attr("src", thisClass.listData[n]["이미지"]);
				$(this).find("td:eq(1) p:first span").html(thisClass.listData[n]["닉네임"]);
				$(this).find("td:eq(1) li:eq(0)").attr("class", szClass).html(thisClass.listData[n]["성별"]);
				$(this).find("td:eq(1) li:eq(1)>span").html(thisClass.listData[n]["핸디"]);
				$(this).find("td:eq(1) li:eq(2)>span").html(thisClass.listData[n]["비거리"]);
				$(this).find("td:eq(2) p:eq(0)>span").html(thisClass.listData[n]["함께아는사람"]);
				$(this).find("td:eq(2) p:eq(1)").html(thisClass.listData[n]["전"]);
			});
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("table").hide();
			if($layer.find("#tmpSpin").length == 0){
				$layer.append("<div id='tmpSpin' style='position:relative; width:800px; height:300px;'></div>");
			}
			$layer.find("#tmpSpin").spin().show();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("#tmpSpin").spin(false).hide();
			$layer.find("table").show();
		}
	}
	
	// 서버통신
	function clsComm()
	{
		this.friendRequestList = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.friendRequestList = [
//				{
//					"키": null
//					, "이미지": null
//					, "아이디": null
//					, "닉네임": null
//					, "성별": null
//					, "핸디": null
//					, "비거리": null
//					, "함께아는사람": null
//					, "전": null
//				}
			];
		}
		, getFriendRequestList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.friendRequestList = [
					{
						"키": "001"
						, "이미지": "../images/board/default_50_50.gif"
						, "아이디": "sky72"
						, "닉네임": "오스케 짱말짱"
						, "성별": "남자"
						, "핸디": "100"
						, "비거리": "150"
						, "함께아는사람": "베짱이 멋쨍이"
						, "전": "5시간 전"
					}
					, {
						"키": "002"
						, "이미지": "../images/board/default_50_50.gif"
						, "아이디": "sky73"
						, "닉네임": "오스케 짱말짱1"
						, "성별": "남자"
						, "핸디": "200"
						, "비거리": "250"
						, "함께아는사람": "베짱이 멋쨍이1"
						, "전": "1시간 전"
					}
					, {
						"키": "003"
						, "이미지": "../images/board/default_50_50.gif"
						, "아이디": "sky72"
						, "닉네임": "오스케 짱말짱2"
						, "성별": "여자"
						, "핸디": "100"
						, "비거리": "150"
						, "함께아는사람": "베짱이 멋쨍이2"
						, "전": "2시간 전"
					}
					, {
						"키": "004"
						, "이미지": "../images/board/default_50_50.gif"
						, "아이디": "sky72"
						, "닉네임": "오스케 짱말짱3"
						, "성별": "남자"
						, "핸디": "200"
						, "비거리": "250"
						, "함께아는사람": "베짱이 멋쨍이3"
						, "전": "3시간 전"
					}
					, {
						"키": "005"
						, "이미지": "../images/board/default_50_50.gif"
						, "아이디": "sky72"
						, "닉네임": "오스케 짱말짱4"
						, "성별": "남자"
						, "핸디": "100"
						, "비거리": "150"
						, "함께아는사람": "베짱이 멋쨍이4"
						, "전": "4시간 전"
					}
				];
				
				$(thisClass).trigger("evtFinishFriendRequestList");
			}, 500);
		}
		, getFriendRequestData: function(){
			return this.friendRequestList;
		}
	}
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objList = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objComm = new clsComm();
			this.objList = new clsList();
			
			this._bind();
			
			this.objList.spinStart();
			this.objComm.getFriendRequestList();
		}
		, _bind: function(){
			var thisClass = this;
			
			$(this.objComm).bind("evtFinishFriendRequestList", function(){
				var thisData = this.getFriendRequestData();
				
				thisClass.objList.spinEnd();
				thisClass.objList.setData(thisData);
			});
		}
	}
	
	document.objControl = new clsControl();
});
